using UnityEngine;
using System.Collections;

public class Cart : MonoBehaviour {

	public Terminal startTerminal {get; set;}
	
	//This doesn't work. It is supposed to check if the cart is colliding with the target terminal (or any terminal right now) and slow it down if so,
	//  but the collision isn't being passed up from the wheels to the top-level of the cart.
	void OnTriggerStay(Collider other) {
		Terminal terminal = (other.gameObject.transform.parent.GetComponentInChildren<Terminal>() as Terminal);
        if (terminal != null)
		{
			rigidbody.velocity = Vector3.Lerp (rigidbody.velocity, Vector3.zero, 0.1f/Vector3.Distance(transform.position, terminal.coord));
			if(rigidbody.velocity.magnitude < 1 && Vector3.Distance(transform.position, terminal.coord) < 5)
			{
				rigidbody.constraints = RigidbodyConstraints.FreezeAll;
			}
		}
	}
}
